#include "formatcommand.h"

#include <QDomDocument>
#include <QDebug>
extern "C"
{
#include <windows.h>
}

FormatCommand::FormatCommand(const QString &formatDrive)
{
	m_FormatDrive = formatDrive.toLower().remove("\\");
}

bool FormatCommand::doCommand(QString &responseData)
{
	qDebug()<<"Format "<<m_FormatDrive;

	int result = 0;

	QString formatStr = "format " + m_FormatDrive + " /FS:NTFS /Q /X /y";
	std::string  stdStr = formatStr.toStdString();
	const char* formatC = stdStr.c_str();
	int exitCode = ::system(formatC);
	result = exitCode == 0 ? 1 : 0;

	QDomDocument resultXml;
	QDomElement rootElement = resultXml.createElement("Result");
	resultXml.appendChild(rootElement);
	rootElement.setAttribute("Result", result);
	responseData.append( resultXml.toString() );
	return true;
}
